package com.ruoyi.project.propertySystem.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.propertySystem.domain.InspectClassify;
import com.ruoyi.project.propertySystem.service.IInspectClassifyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 巡检分类Controller
 * 
 * @author wangshuo
 * @date 2021-01-18
 */
@RestController
@RequestMapping("/propertySystem/inspectClassify")
public class InspectClassifyController extends BaseController
{
    @Autowired
    private IInspectClassifyService inspectClassifyService;

    /**
     * 查询巡检分类列表
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:inspectClassify:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectClassify inspectClassify)
    {
        startPage();
        List<InspectClassify> list = inspectClassifyService.selectInspectClassifyList(inspectClassify);
        return getDataTable(list);
    }

    /**
     * 导出巡检分类列表
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:inspectClassify:export')")
    @Log(title = "巡检分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(InspectClassify inspectClassify)
    {
        List<InspectClassify> list = inspectClassifyService.selectInspectClassifyList(inspectClassify);
        ExcelUtil<InspectClassify> util = new ExcelUtil<InspectClassify>(InspectClassify.class);
        return util.exportExcel(list, "inspectClassify");
    }

    /**
     * 获取巡检分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:inspectClassify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(inspectClassifyService.selectInspectClassifyById(id));
    }

    /**
     * 新增巡检分类
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:inspectClassify:add')")
    @Log(title = "巡检分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectClassify inspectClassify)
    {
        return toAjax(inspectClassifyService.insertInspectClassify(inspectClassify));
    }

    /**
     * 修改巡检分类
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:inspectClassify:edit')")
    @Log(title = "巡检分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectClassify inspectClassify)
    {
        inspectClassify.setModifyBy(SecurityUtils.getUsername());
        inspectClassify.setGmtModify(new Date());
        return toAjax(inspectClassifyService.updateInspectClassify(inspectClassify));
    }

    /**
     * 删除巡检分类
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:inspectClassify:remove')")
    @Log(title = "巡检分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectClassifyService.deleteInspectClassifyByIds(ids));
    }
}
